<?php
/*************************************************************************************
 *
 *	FileName: WebUI.php
 *	Desc    : This class helps to construct and change the state of some UI in Web page
 *	Author  : Seal
 *	Date    : 2010-1-10
 *
 *************************************************************************************/

	class WebUI
	{
		private $scriptContent = "";
		private $variables = array();
		
		public function AddComponent( $id, $value, $type )
		{
			switch($type)
			{
				case "text":
				case "select":
					$this->scriptContent .= "$('#$id').val('$value');";
					break;
			
				default: break;
			}
		}
		
		public function AssignGlobalVariable( $name, $value )
		{
			$this->variables[] = array(
				'name' => $name,
				'value' => $value
			);
		}
		
		
		public function OutputScripts()
		{
			return $this->scriptContent;
		}
		
		public function OutputVariables()
		{
			$statement = '';
			foreach( $this->variables as $variable )
				$statement .= ' var ' . $variable['name'] . '=' . $variable['value'] . ';';
				
			return $statement;
		}
	
	}

?>